using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;

namespace IRL.Utilities
{

    public class Lookup
    {
        public static Hashtable Fill(string sql, SqlConnection conn)
        {
            Hashtable Temp = new Hashtable();
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataReader dr;
            bool closedConn = false;
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
                closedConn = true;
            }
            dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                Temp.Add(dr[0].ToString(), dr[1].ToString());
            }
            dr.Close();
            if (closedConn)
                conn.Close();
            return Temp;
        }

        public static string GetText(string sql, SqlConnection conn)
        {
            SqlCommand cmd = new SqlCommand(sql, conn);
            bool closedConn = false;
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
                closedConn = true;
            }
            string value = (string)cmd.ExecuteScalar();
            if (closedConn)
                conn.Close();
            return (value == null ? "" : value);
        }
    }
}
